package com.qiu.wxapi.service;

import com.qiu.wxapi.mapper.SignInMapper;
import com.qiu.wxapi.mapper.UserMapper;
import com.qiu.wxapi.pojo.SignIn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class SignInService {
    @Autowired
    private SignInMapper signInMapper;
    @Autowired
    private UserMapper userMapper;

    /**
     * 保存
     * @param signIn
     */
    public void insertSelective(SignIn signIn) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        signIn.setDate(format);

        this.signInMapper.insertSelective(signIn);
    }

    /**
     * 查询打卡信息
     * @return
     */
    public List<SignIn> selectAll(Integer userId) {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String format = simpleDateFormat.format(new Date());
        SignIn signIn = new SignIn();
        signIn.setUserId(userId);
        signIn.setDate(format);
        List<SignIn> select = this.signInMapper.select(signIn);
        return select;
    }
}
